export default {
    namespaced: 'tag',
    state: () => ({
        tabList: JSON.parse(sessionStorage.getItem('tab-history')) ? JSON.parse(sessionStorage.getItem('tab-history')) : [
            {
               path: '/dashboard',
               name: '数据统计', 
            }
        ],
    }),
    mutations: {
        saveHistory(state) {
            sessionStorage.setItem('tab-history', JSON.stringify(state.tabList))
        },
        changeMenu(state, tag) {
            console.log(tag);
            if (tag.name !== '数据统计') {
                const index = state.tabList.every(item => item.name != tag.name)
                if(index) {
                    state.tabList.push(tag)
                }
                this.commit('tag/saveHistory')
            }
        },
        closeTag(state, tag) {
            const index = state.tabList.findIndex(item => item.name === tag.name)
            state.tabList.splice(index, 1)
            this.commit('tag/saveHistory')
        }
    }
}